package db

import (
	models "doc-service/modes"
	"doc-service/service"
)

type DocServerProject struct {
	Id          int    `db:"id" gorm:"primaryKey"`
	ProjectName string `db:"project_name"`
	SourceType  string `db:"source_type"`
	TargetType  string `db:"target_type"`
	SourceUrl   string `db:"source_url"`
	TargetUrl   string `db:"target_url"`
	TaskId      string `db:"task_id"`
	AppId       int    `db:"app_id"`
	Status      int    `db:"status"`
	CreatedAt   string `db:"created_at"`
}

func (a DocServerProject) TableName() string {
	return "doc_server_project"
}

func SaveProject(req service.ConversionRequest, result string) int {
	//入库
	insertProject := &DocServerProject{}
	insertProject.ProjectName = req.ProjectName
	insertProject.SourceType = req.SourceType
	insertProject.TargetType = req.TargetType
	insertProject.SourceUrl = req.SourceURI
	insertProject.TargetUrl = req.TargetURI
	insertProject.Status = 0
	insertProject.AppId = 1
	insertProject.CreatedAt = models.GetDate()
	insertProject.TaskId = result
	models.DB.Create(insertProject)
	return 0
}
