package dto

import (
	"time"

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

type CooperationProjectInfo struct {
	Company struct {
		CompanyId   int    `json:"companyId,string,"`
		CompanyLogo string `json:"companyLogo"`
		CompanyName string `json:"companyName"`
	} `json:"company"` //项目归属企业
	Org struct {
		OrgId   int    `json:"orgId"`
		OrgName string `json:"orgName"`
	} `json:"org"` //项目创建时的组织
	CooperationMode struct {
		CooperationModeId     int    `json:"cooperationModeId,string,"`
		CooperationModeName   string `json:"cooperationModeName"`
		CooperationModeNumber string `json:"cooperationModeNumber"`
	} `json:"cooperationMode"` //项目模式
	CooperationProjectDescription string `json:"cooperationProjectDescription"`
	Attachment                    []struct {
		FileType string `json:"fileType"`
		Name     string `json:"name"`
		Url      string `json:"url"`
		FileSize int    `json:"fileSize"`
	} `json:"attachment"` //图片附件
	CooperationProjectId          int       `json:"cooperationProjectId,string,"`
	CooperationProjectName        string    `json:"cooperationProjectName"`
	CooperationProjectNumber      string    `json:"cooperationProjectNumber"`
	CooperationProjectPublishTime time.Time `json:"cooperationProjectPublishTime"`
	CreatedAt                     time.Time `json:"createdAt"`
	CooperationProjectSponsor     struct {
		UsersId   int    `json:"usersId"`
		UsersName string `json:"usersName"`
		UsersCode string `json:"usersCode"`
		UserInfo  struct {
			UsersName string `json:"usersName"`
			UsersCode string `json:"usersCode"`
			Phone     string `json:"phone"`
			UsersId   int    `json:"userId,string,"`
		} `json:"userInfo"`
	} `json:"cooperationProjectSponsor"` //项目发起人
	CooperationProjectUndertakerType []int `json:"cooperationProjectUndertakerType"` //共创合约承接对象,1员工,2共创用户,3公开
	Department                       struct {
		DepartmentNumber string `json:"departmentNumber"`
		DepartmentId     int    `json:"departmentId,string,"`
		DepartmentName   string `json:"departmentName"`
	} `json:"department"` //项目发起部门
	Status int `json:"status"` // 共创项目状态,1招标中,2结束

}

func ToCooperationProjectInfo(param *allied_creation_cooperation.CooperationProject) *CooperationProjectInfo {
	data := CooperationProjectInfo{
		Company:                          param.Company,
		Org:                              param.Org,
		CooperationMode:                  param.CooperationMode,
		CooperationProjectDescription:    param.CooperationProjectDescription,
		Attachment:                       param.Attachment,
		CooperationProjectId:             param.CooperationProjectId,
		CooperationProjectName:           param.CooperationProjectName,
		CooperationProjectNumber:         param.CooperationProjectNumber,
		CooperationProjectPublishTime:    param.CooperationProjectPublishTime,
		CreatedAt:                        param.CreatedAt,
		CooperationProjectUndertakerType: param.CooperationProjectUndertakerType,
		Department:                       param.Department,
		Status:                           param.Status,
	}
	data.CooperationProjectSponsor.UsersCode = param.CooperationProjectSponsor.UserInfo.UsersCode
	data.CooperationProjectSponsor.UsersName = param.CooperationProjectSponsor.UserInfo.UsersName
	data.CooperationProjectSponsor.UsersId = param.CooperationProjectSponsor.UsersId
	data.CooperationProjectSponsor.UserInfo = param.CooperationProjectSponsor.UserInfo
	return &data
}

type CooperationApplication struct {
	CooperationApplicationApplicant struct {
		Company struct {
			CompanyID   int    `json:"companyId"`
			CompanyLogo string `json:"companyLogo"`
			CompanyName string `json:"companyName"`
		} `json:"company"`
		Department struct {
			DepartmentID     int    `json:"departmentId"`
			DepartmentName   string `json:"departmentName"`
			DepartmentNumber string `json:"departmentNumber"`
		} `json:"department"`
		Org struct {
			OrgID   int    `json:"orgId"`
			OrgName string `json:"orgName"`
		} `json:"org"`
		UserBaseID int `json:"userBaseId"`
		UserID     int `json:"userId"`
		UserInfo   struct {
			UserAccount string `json:"userAccount"`
			UserAvatar  string `json:"userAvatar"`
			UserEmail   string `json:"userEmail"`
			UserName    string `json:"userName"`
			UserPhone   string `json:"userPhone"`
		} `json:"userInfo"`
		UserType int `json:"userType"`
	} `json:"cooperationApplicationApplicant"` //申请人
	CooperationApplicationDescription string `json:"cooperationApplicationDescription"` //描述
	CooperationApplicationID          int    `json:"cooperationApplicationId"`          //申请id
	CooperationApplicationStatus      int    `json:"cooperationApplicationStatus"`      //状态
	CooperationApplyTime              int    `json:"cooperationApplyTime"`              //申请时间
	CooperationApplicationAttachment  []struct {
		FileSize float64 `json:"fileSize"`
		FileType string  `json:"fileType"`
		Name     string  `json:"name"`
		URL      string  `json:"url"`
	} `json:"cooperationApplicationAttachment"` //附件
}

func ToCooperationApplication(param *allied_creation_cooperation.CooperationApplication) *CooperationApplication {
	data := CooperationApplication{
		CooperationApplicationApplicant:   param.CooperationApplicationApplicant,
		CooperationApplicationDescription: param.CooperationApplicationDescription,
		CooperationApplicationID:          param.CooperationApplicationID,
		CooperationApplicationStatus:      param.CooperationApplicationStatus,
		CooperationApplyTime:              int(param.CooperationApplyTime.Unix()),
		CooperationApplicationAttachment:  param.CooperationApplicationAttachment,
	}
	return &data
}