package net.shyshkin.study.fullstack.supportportal.backend.mapper;

import net.shyshkin.study.fullstack.supportportal.backend.domain.Professor;
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.ProfessorDto;
import net.shyshkin.study.fullstack.supportportal.backend.domain.WorkingStatus;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

@Mapper(componentModel = "spring")
public interface ProfessorMapper {

    // @Mapping(target = "professorId", ignore = true) // Auto-generated
    @Mapping(target = "joinDate", expression = "java(java.time.LocalDateTime.now())") // Default value
    @Mapping(target = "status", source = "status", qualifiedByName = "stringToWorkingStatus")
    Professor toEntity(ProfessorDto professorDto);

    @Mapping(target = "profileImage", ignore = true) // Ignore profileImage mapping
    @Mapping(target = "status", source = "status", qualifiedByName = "workingStatusToString")
    ProfessorDto toDto(Professor professor);

    @Named("stringToWorkingStatus")
    default WorkingStatus stringToWorkingStatus(String status) {
        return status == null ? null : WorkingStatus.valueOf(status);
    }

    @Named("workingStatusToString")
    default String workingStatusToString(WorkingStatus status) {
        return status == null ? null : status.name();
    }
    
}

