package com.eactive.eai.common.duplication.mapper;

import java.time.DayOfWeek;
import java.time.LocalDate;

import org.mapstruct.AfterMapping;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

import com.eactive.eai.common.duplication.DuplicationGuidLogVo;
import com.eactive.eai.data.entity.onl.duplication.DuplicationGuidLog;
import com.eactive.eai.data.mapper.BaseMapperConfig;
import com.eactive.eai.data.mapper.GenericMapper;

@Mapper(config = BaseMapperConfig.class)
public interface DuplicationGuidLogMapper extends GenericMapper<DuplicationGuidLogVo, DuplicationGuidLog> {

    @Override
    @Mapping(source = "id.guid", target = "guid")
    @Mapping(source = "id.channel_code", target = "channelCode")
    @Mapping(source = "recv_datetime", target = "recvDatetime")
    @Mapping(source = "instance_name", target = "instanceName")
    DuplicationGuidLogVo toVo(DuplicationGuidLog entity);

    @Override
    @InheritInverseConfiguration
    DuplicationGuidLog toEntity(DuplicationGuidLogVo vo);
    
    @AfterMapping
    default void setCheckIdAndWeekday(@MappingTarget DuplicationGuidLog entity, DuplicationGuidLogVo vo) {
        DayOfWeek dayOfWeek = LocalDate.now().getDayOfWeek(); // 현재 요일
        int dayOfWeekNumber = dayOfWeek.getValue() % 7 + 1; // 1 (일요일)부터 7 (토요일)까지
        entity.getId().setWeekday(dayOfWeekNumber);
    }
    
}