package vn.azteam.tpf.service.mapper;

import vn.azteam.tpf.domain.*;
import vn.azteam.tpf.service.dto.TBPermissionDTO;

import org.mapstruct.*;

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

    @Mapping(source = "tbFunction.id", target = "tbFunctionId")
    @Mapping(source = "tbRole.id", target = "tbRoleId")
    @Mapping(source = "createdBy.id", target = "createdById")
    @Mapping(source = "modifiedBy.id", target = "modifiedById")
    @Mapping(source = "deletedBy.id", target = "deletedById")
    @Mapping(source = "tbFunction.name", target = "name")
    @Mapping(target = "casbinDTOList",ignore = true)
    TBPermissionDTO toDto(TBPermission tBPermission);

    @Mapping(source = "tbFunctionId", target = "tbFunction")
    @Mapping(source = "tbRoleId", target = "tbRole")
    @Mapping(source = "createdById", target = "createdBy")
    @Mapping(source = "modifiedById", target = "modifiedBy")
    @Mapping(source = "deletedById", target = "deletedBy")
    TBPermission toEntity(TBPermissionDTO tBPermissionDTO);

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