package dto

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)

//合约模式
type CooperationMode struct {
	CooperationModeId     int    `json:"cooperationModeId,string"`
	CooperationModeName   string `json:"cooperationModeName"`
	CooperationModeNumber string `json:"cooperationModeNumber"`
}

//部门
type Department struct {
	DepartmentNumber string `json:"departmentNumber"`
	DepartmentId     int    `json:"departmentId,string,"`
	DepartmentName   string `json:"departmentName"`
}

//用户
type UserInfo struct {
	UsersName string `json:"usersName"`
	Phone     string `json:"phone"`
	UsersId   int    `json:"userId,string"`
}

//CooperationProjectItem 返回共创项目列表项
type CooperationProjectItem struct {
	CooperationMode                  CooperationMode `json:"cooperationMode"`                  //项目模式
	CooperationProjectID             int             `json:"cooperationProjectId,string,"`     //id
	CooperationProjectName           string          `json:"cooperationProjectName"`           //共创项目名称
	CooperationProjectNumber         string          `json:"cooperationProjectNumber"`         //项目编号
	CooperationProjectUndertakerType []int           `json:"cooperationProjectUndertakerType"` //承接对象
	Department                       Department      `json:"department"`                       //项目发起部门
	Status                           int             `json:"status"`                           //项目状态
	CooperationProjectPublishTime    int             `json:"cooperationProjectPublishTime"`
	CooperationProjectSponsor        struct {
		UsersId  int      `json:"usersId"`
		UserInfo UserInfo `json:"UserInfo"`
	} `json:"cooperationProjectSponsor"` //共创发起人
}

func ToCooperationProjectItem(projecetParam *allied_creation_cooperation.CooperationProject) *CooperationProjectItem {
	data := CooperationProjectItem{
		CooperationMode:                  projecetParam.CooperationMode,
		CooperationProjectID:             projecetParam.CooperationProjectId,
		CooperationProjectName:           projecetParam.CooperationProjectName,
		CooperationProjectNumber:         projecetParam.CooperationProjectNumber,
		CooperationProjectUndertakerType: projecetParam.CooperationProjectUndertakerType,
		Department:                       projecetParam.Department,
		Status:                           projecetParam.Status,
		CooperationProjectPublishTime:    int(projecetParam.CooperationProjectPublishTime.Unix()),
	}
	data.CooperationProjectSponsor.UsersId = projecetParam.CooperationProjectSponsor.UsersId
	data.CooperationProjectSponsor.UserInfo.UsersId = projecetParam.CooperationProjectSponsor.UsersId
	data.CooperationProjectSponsor.UserInfo.Phone = projecetParam.CooperationProjectSponsor.UserInfo.Phone
	data.CooperationProjectSponsor.UserInfo.UsersName = projecetParam.CooperationProjectSponsor.UserInfo.UsersName
	return &data
}

//CooperationProjectInfo 返回共创项目详情
type CooperationProjectInfo struct {
	CooperationMode                  CooperationMode `json:"cooperationMode"`                  //共创模式
	CooperationProjectID             int             `json:"cooperationProjectId,string,"`     //id
	CooperationProjectName           string          `json:"cooperationProjectName"`           //共创项目名称
	CooperationProjectNumber         string          `json:"cooperationProjectNumber"`         //项目编号
	CooperationProjectPublishTime    int             `json:"cooperationProjectPublishTime"`    //共创项目发布时间
	CooperationProjectUndertakerType []int           `json:"cooperationProjectUndertakerType"` //承接对象
	CooperationProjectDescription    string          `json:"cooperationProjectDescription"`    //共创描述
	Department                       Department      `json:"department"`                       //项目发起部门
	Status                           int             `json:"status"`                           //项目状态
	CooperationProjectSponsor        struct {
		UsersId  int      `json:"usersId"`
		UserInfo UserInfo `json:"UserInfo"`
	} `json:"cooperationProjectSponsor"` //共创发起人
	Attachment []domain.Attachment `json:"attachment"` //图片附件
}

func ToCooperationProjectInfo(projecetParam *allied_creation_cooperation.CooperationProject) *CooperationProjectInfo {
	data := CooperationProjectInfo{
		CooperationMode:                  projecetParam.CooperationMode,
		CooperationProjectID:             projecetParam.CooperationProjectId,
		CooperationProjectName:           projecetParam.CooperationProjectName,
		CooperationProjectNumber:         projecetParam.CooperationProjectNumber,
		CooperationProjectUndertakerType: projecetParam.CooperationProjectUndertakerType,
		Department:                       projecetParam.Department,
		Status:                           projecetParam.Status,
		CooperationProjectPublishTime:    int(projecetParam.CooperationProjectPublishTime.Unix()),
		Attachment:                       projecetParam.Attachment,
		CooperationProjectDescription:    projecetParam.CooperationProjectDescription,
	}
	data.CooperationProjectSponsor.UsersId = projecetParam.CooperationProjectSponsor.UsersId
	data.CooperationProjectSponsor.UserInfo.UsersId = projecetParam.CooperationProjectSponsor.UsersId
	data.CooperationProjectSponsor.UserInfo.Phone = projecetParam.CooperationProjectSponsor.UserInfo.Phone
	data.CooperationProjectSponsor.UserInfo.UsersName = projecetParam.CooperationProjectSponsor.UserInfo.UsersName

	return &data
}

type CooperationApplication struct {
	CooperationApplicationApplicant struct {
		UserId     int        `json:"userId"`
		UserInfo   UserInfo   `json:"userInfo"`
		Department Department `json:"department"` //申请人部门
	} `json:"cooperationApplicationApplicant"` //申请人
	CooperationApplicationAttachment        []domain.Attachment `json:"cooperationApplicationAttachment"`        //附件信息
	CooperationApplicationDescription       string              `json:"cooperationApplicationDescription"`       //申请描述
	CooperationApplicationVerifyDescription string              `json:"cooperationApplicationVerifyDescription"` //审核描述
	CooperationApplicationId                int                 `json:"cooperationApplicationId"`                //申请id
	CooperationApplicationStatus            int                 `json:"cooperationApplicationStatus"`            //审核状态
	CooperationApplicationVerifyTime        int                 `json:"cooperationApplicationVerifyTime"`        //审核的时间
	CooperationProjectId                    int                 `json:"cooperationProjectId"`                    //项目id
	CooperationProjectName                  string              `json:"cooperationProjectName"`
	CooperationProjectNumber                string              `json:"cooperationProjectNumber"`
}

func ToCooperationApplication(applicationParam *allied_creation_cooperation.CooperationApplication) *CooperationApplication {
	data := CooperationApplication{
		CooperationApplicationAttachment:        applicationParam.CooperationApplicationAttachment, //附件信息
		CooperationApplicationDescription:       applicationParam.CooperationApplicationDescription,
		CooperationApplicationId:                applicationParam.CooperationApplicationID,
		CooperationApplicationStatus:            applicationParam.CooperationApplicationStatus,                 //共创申请审核状态,1待审核,2已同意,3已拒绝
		CooperationApplicationVerifyTime:        int(applicationParam.CooperationApplicationVerifyTime.Unix()), //审核的时间
		CooperationProjectId:                    applicationParam.CooperationProject.CooperationProjectID,
		CooperationProjectName:                  applicationParam.CooperationProject.CooperationProjectName,
		CooperationProjectNumber:                applicationParam.CooperationProject.CooperationProjectNumber,
		CooperationApplicationVerifyDescription: applicationParam.CooperationApplicationVerifyDescription,
	}

	data.CooperationApplicationApplicant.UserId = applicationParam.CooperationApplicationApplicant.UserID
	data.CooperationApplicationApplicant.UserInfo.Phone = applicationParam.CooperationApplicationApplicant.UserInfo.UserPhone
	data.CooperationApplicationApplicant.UserInfo.UsersName = applicationParam.CooperationApplicationApplicant.UserInfo.UserName
	data.CooperationApplicationApplicant.UserInfo.UsersId = applicationParam.CooperationApplicationApplicant.UserID
	data.CooperationApplicationApplicant.Department.DepartmentId = applicationParam.CooperationApplicationApplicant.Department.DepartmentID
	data.CooperationApplicationApplicant.Department.DepartmentName = applicationParam.CooperationApplicationApplicant.Department.DepartmentName
	data.CooperationApplicationApplicant.Department.DepartmentNumber = applicationParam.CooperationApplicationApplicant.Department.DepartmentNumber
	return &data

}