package divisionposition

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ed "simrs-vx/internal/domain/main-entities/division"
	ee "simrs-vx/internal/domain/main-entities/employee"
)

type CreateDto struct {
	Division_Code *string `json:"division_code"`
	Code          string  `json:"code" validate:"maxLength=10"`
	Name          string  `json:"name" validate:"maxLength=50"`
	HeadStatus    bool    `json:"headStatus"`
	Employee_Id   *uint   `json:"employee_id"`
}

type ReadListDto struct {
	FilterDto
	Includes   string `json:"includes"`
	Sort       string `json:"sort"`
	Pagination ecore.Pagination
}

type FilterDto struct {
	Division_Code *string `json:"division-code"`
	Code          string  `json:"code"`
	Name          string  `json:"name"`
	HeadStatus    *bool   `json:"head-status"`
	Employee_Id   *uint   `json:"employee-id"`
	Search        string  `json:"search" gormhelper:"searchColumns=Code,Name"`
}

type ReadDetailDto struct {
	Id   *uint16 `json:"id"`
	Code *string `json:"code"`
}

type UpdateDto struct {
	Id *uint16 `json:"id"`
	CreateDto
}

type DeleteDto struct {
	Id   *uint16 `json:"id"`
	Code *string `json:"code"`
}

type MetaDto struct {
	PageNumber int `json:"page_number"`
	PageSize   int `json:"page_size"`
	Count      int `json:"count"`
}

type ResponseDto struct {
	ecore.SmallMain
	Division_Code *string      `json:"division_code"`
	Division      *ed.Division `json:"division,omitempty"`
	Code          string       `json:"code"`
	Name          string       `json:"name"`
	HeadStatus    bool         `json:"headStatus"`
	Employee_Id   *uint        `json:"employee_id"`
	Employee      *ee.Employee `json:"employee,omitempty"`
}

func (d DivisionPosition) ToResponse() ResponseDto {
	resp := ResponseDto{
		Division_Code: d.Division_Code,
		Code:          d.Code,
		Name:          d.Name,
		HeadStatus:    d.HeadStatus,
		Employee_Id:   d.Employee_Id,
		Employee:      d.Employee,
	}
	resp.SmallMain = d.SmallMain
	if d.Division != nil {
		resp.Division = d.Division
	}
	return resp
}

func ToResponseList(data []DivisionPosition) []ResponseDto {
	resp := make([]ResponseDto, len(data))
	for i, u := range data {
		resp[i] = u.ToResponse()
	}
	return resp
}
