package language

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
)

type CreateDto struct {
	Code *string `json:"code" validate:"maxLength=10"`
	Name string  `json:"name" validate:"maxLength=50"`
}

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

type FilterDto struct {
	Code   string `json:"code"`
	Name   string `json:"name"`
	Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
}

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

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.Main
	Code string `json:"code"`
	Name string `json:"name"`
}

func (d Language) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code: d.Code,
		Name: d.Name,
	}
	resp.Main = d.Main
	return resp
}

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