package vn.azteam.tpf.service.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import vn.azteam.tpf.domain.Casbin;
import vn.azteam.tpf.service.dto.CasbinDTO;

/**
 * Mapper for the entity Casbin and its DTO CasbinDTO.
 */
@Mapper(componentModel = "spring", uses = {TBRoleMapper.class, TBFunctionMapper.class, TBDetailUserMapper.class})
public interface CasbinMapper extends EntityMapper<CasbinDTO, Casbin> {

    @Mapping(source = "tbRole.id", target = "tbRoleId")
    @Mapping(source = "tbFunction.id", target = "tbFunctionId")
    @Mapping(source = "createdBy.id", target = "createdById")
    @Mapping(source = "modifiedBy.id", target = "modifiedById")
    @Mapping(source = "deletedBy.id", target = "deletedById")
    CasbinDTO toDto(Casbin casbin);

    @Mapping(source = "tbRoleId", target = "tbRole")
    @Mapping(source = "tbFunctionId", target = "tbFunction")
    @Mapping(source = "createdById", target = "createdBy")
    @Mapping(source = "modifiedById", target = "modifiedBy")
    @Mapping(source = "deletedById", target = "deletedBy")
    Casbin toEntity(CasbinDTO casbinDTO);

    default Casbin fromId(Long id) {
        if (id == null) {
            return null;
        }
        Casbin casbin = new Casbin();
        casbin.setId(id);
        return casbin;
    }
}
