package com.aircraft.modules.aircraft.service.impl;

import com.aircraft.exception.BadRequestException;
import com.aircraft.modules.aircraft.domain.AircraftInsurance;
import com.aircraft.modules.aircraft.domain.AircraftMaintenance;
import com.aircraft.modules.aircraft.mapper.AircraftMaintenanceMapper;
import com.aircraft.modules.aircraft.service.AircraftMaintenanceService;
import com.aircraft.utils.SecurityUtils;
import com.aircraft.utils.enums.UserTypeEnum;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 飞行器维保表 服务实现类
 * </p>
 *
 * @author cli
 * @since 2025-07-11
 */
@Service
public class AircraftMaintenanceServiceImpl extends ServiceImpl<AircraftMaintenanceMapper, AircraftMaintenance> implements AircraftMaintenanceService {

    @Override
    public IPage<AircraftMaintenance> page(Long aircraftId, Page<AircraftMaintenance> page) {
        return lambdaQuery()
                .eq(AircraftMaintenance::getAircraftId, aircraftId)
                .orderByDesc(AircraftMaintenance::getId)
                .page(page);
    }

    @Override
    public void create(AircraftMaintenance aircraftMaintenance) {
       if (!UserTypeEnum.EMPLOYEES.equals(SecurityUtils.getCurrentUserType())){
           throw new BadRequestException("非飞行端用户！");
       }
        aircraftMaintenance.setEmployeesId(SecurityUtils.getCurrentUserId());
        save(aircraftMaintenance);
    }
}
