package mappers

import (
	"apskel-pos-be/internal/entities"
	"apskel-pos-be/internal/models"
)

func ChartOfAccountTypeEntityToResponse(entity *entities.ChartOfAccountType) *models.ChartOfAccountTypeResponse {
	return &models.ChartOfAccountTypeResponse{
		ID:          entity.ID,
		Name:        entity.Name,
		Code:        entity.Code,
		Description: entity.Description,
		IsActive:    entity.IsActive,
		CreatedAt:   entity.CreatedAt,
		UpdatedAt:   entity.UpdatedAt,
	}
}

func ChartOfAccountTypeCreateRequestToEntity(req *models.CreateChartOfAccountTypeRequest) *entities.ChartOfAccountType {
	return &entities.ChartOfAccountType{
		Name:        req.Name,
		Code:        req.Code,
		Description: req.Description,
		IsActive:    true,
	}
}

func ChartOfAccountTypeUpdateRequestToEntity(entity *entities.ChartOfAccountType, req *models.UpdateChartOfAccountTypeRequest) {
	if req.Name != nil {
		entity.Name = *req.Name
	}
	if req.Code != nil {
		entity.Code = *req.Code
	}
	if req.Description != nil {
		entity.Description = req.Description
	}
	if req.IsActive != nil {
		entity.IsActive = *req.IsActive
	}
}
