package dto

import (
	"time"

	"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 CooperationApplicationItem struct {
	CooperationProject struct {
		CooperationProjectID     int    `json:"cooperationProjectId"`     //共创项目
		CooperationProjectName   string `json:"cooperationProjectName"`   //共创名称
		CooperationProjectNumber string `json:"cooperationProjectNumber"` //共创编号
	} `json:"cooperationProject"`
	CooperationApplicationApplicant struct {
		UserName       string `json:"userName"` //申请人名字
		UserCode       string `json:"userCode"`
		DepartmentName string `json:"departmentName"` //申请人部门
		Phone          string `json:"userPhone"`      //申请人电话
	} `json:"cooperationApplicationApplicant"`
	CooperationApplicationAttachment        []domain.Attachment `json:"cooperationApplicationAttachment"`        //附件
	CooperationApplicationDescription       string              `json:"cooperationApplicationDescription"`       //描述
	CooperationApplicationID                int                 `json:"cooperationApplicationId"`                //id
	IsCanceled                              bool                `json:"isCanceled"`                              //是否取消
	CooperationApplicationVerifyDescription string              `json:"cooperationApplicationVerifyDescription"` //审核描述
	CooperationApplicationVerifyTime        time.Time           `json:"cooperationApplicationVerifyTime"`        //审核时间
	CooperationApplicationStatus            int                 `json:"cooperationApplicationStatus"`            //申请状态
	Org                                     struct {
		OrgID   int    `json:"orgId"`
		OrgName string `json:"orgName"`
	} `json:"org"` //组织
}

func ToCooperationApplicationItem(param *allied_creation_cooperation.CooperationApplication) *CooperationApplicationItem {
	data := CooperationApplicationItem{

		CooperationApplicationAttachment:        param.CooperationApplicationAttachment,
		CooperationApplicationDescription:       param.CooperationApplicationDescription,
		CooperationApplicationID:                param.CooperationApplicationID,
		IsCanceled:                              param.IsCanceled,
		CooperationApplicationVerifyDescription: param.CooperationApplicationVerifyDescription,
		CooperationApplicationStatus:            param.CooperationApplicationStatus,
		Org:                                     param.Org,
	}
	data.CooperationApplicationApplicant.UserName = param.CooperationApplicationApplicant.UserInfo.UserName
	data.CooperationApplicationApplicant.Phone = param.CooperationApplicationApplicant.UserInfo.UserPhone
	data.CooperationApplicationApplicant.UserCode = param.CooperationApplicationApplicant.UserInfo.UserPhone
	data.CooperationApplicationApplicant.DepartmentName = param.CooperationApplicationApplicant.Department.DepartmentName
	data.CooperationProject.CooperationProjectID = param.CooperationProject.CooperationProjectID
	data.CooperationProject.CooperationProjectName = param.CooperationProject.CooperationProjectName
	data.CooperationProject.CooperationProjectNumber = param.CooperationProject.CooperationProjectNumber
	return &data
}

type CooperationApplicationInfo struct {
	CooperationProject struct {
		CooperationProjectID     int    `json:"cooperationProjectId"`     //共创项目
		CooperationProjectName   string `json:"cooperationProjectName"`   //共创名称
		CooperationProjectNumber string `json:"cooperationProjectNumber"` //共创编号
		CooperationMode          struct {
			CooperationModeId     int    `json:"cooperationModeId,string"`
			CooperationModeName   string `json:"cooperationModeName"`
			CooperationModeNumber string `json:"cooperationModeNumber"`
		} `json:"cooperationMode"` //项目模式
	}
	CooperationApplicationApplicant struct {
		UserName       string `json:"userName"` //申请人名字
		UserCode       string `json:"userCode"`
		DepartmentName string `json:"departmentName"` //申请人部门
		Phone          string `json:"userPhone"`      //申请人电话
	} `json:"cooperationApplicationApplicant"`
	CooperationApplicationAttachment        []domain.Attachment `json:"cooperationApplicationAttachment"`        //附件
	CooperationApplicationDescription       string              `json:"cooperationApplicationDescription"`       //描述
	CooperationApplicationID                int                 `json:"cooperationApplicationId"`                //id
	IsCanceled                              bool                `json:"isCanceled"`                              //是否取消
	CooperationApplicationVerifyDescription string              `json:"cooperationApplicationVerifyDescription"` //审核描述
	CooperationApplicationVerifyTime        time.Time           `json:"cooperationApplicationVerifyTime"`        //审核时间
	CooperationApplicationStatus            int                 `json:"cooperationApplicationStatus"`            //申请状态
	Org                                     struct {
		OrgID   int    `json:"orgId"`
		OrgName string `json:"orgName"`
	} `json:"org"` //组织
}

func ToCooperationApplicationInfo(applicationParam *allied_creation_cooperation.CooperationApplication,
	objectParam *allied_creation_cooperation.CooperationProject) *CooperationApplicationInfo {
	data := CooperationApplicationInfo{
		CooperationApplicationAttachment:        applicationParam.CooperationApplicationAttachment,
		CooperationApplicationDescription:       applicationParam.CooperationApplicationDescription,
		CooperationApplicationID:                applicationParam.CooperationApplicationID,
		IsCanceled:                              applicationParam.IsCanceled,
		CooperationApplicationVerifyDescription: applicationParam.CooperationApplicationVerifyDescription,
		CooperationApplicationStatus:            applicationParam.CooperationApplicationStatus,
		Org:                                     applicationParam.Org,
	}
	data.CooperationProject.CooperationProjectID = objectParam.CooperationProjectId
	data.CooperationProject.CooperationProjectName = objectParam.CooperationProjectName
	data.CooperationProject.CooperationProjectNumber = objectParam.CooperationProjectNumber
	data.CooperationProject.CooperationMode.CooperationModeId = objectParam.CooperationMode.CooperationModeId
	data.CooperationProject.CooperationMode.CooperationModeName = objectParam.CooperationMode.CooperationModeName
	data.CooperationProject.CooperationMode.CooperationModeNumber = objectParam.CooperationMode.CooperationModeNumber
	data.CooperationApplicationApplicant.UserName = applicationParam.CooperationApplicationApplicant.UserInfo.UserName
	data.CooperationApplicationApplicant.Phone = applicationParam.CooperationApplicationApplicant.UserInfo.UserPhone
	data.CooperationApplicationApplicant.UserCode = applicationParam.CooperationApplicationApplicant.UserInfo.UserPhone
	data.CooperationApplicationApplicant.DepartmentName = applicationParam.CooperationApplicationApplicant.Department.DepartmentName
	return &data
}