package cn.iocoder.yudao.module.asset.controller.admin.parking;

import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.asset.controller.admin.parking.vo.ParkingSaveReqVO;
import cn.iocoder.yudao.module.asset.dal.dataobject.parking.ParkingDO;
import cn.iocoder.yudao.module.asset.dal.mysql.parking.ParkingMapper;
import cn.iocoder.yudao.module.asset.service.parking.ParkingServiceImpl;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;

import jakarta.annotation.Resource;

import static org.junit.jupiter.api.Assertions.*;

/**
 * 停车场管理 Service 测试
 */
@Import(ParkingServiceImpl.class)
public class ParkingServiceTest extends BaseDbUnitTest {

    @Resource
    private ParkingServiceImpl parkingService;

    @Resource
    private ParkingMapper parkingMapper;

    @Test
    public void testCreateParking() {
        // 准备参数
        ParkingSaveReqVO reqVO = new ParkingSaveReqVO();
        reqVO.setName("测试停车场");
        reqVO.setAddress("上海市浦东新区");
        reqVO.setCapacity(100);
        reqVO.setParkedAmount(50);

        // 调用
        Long parkingId = parkingService.createParking(reqVO);

        // 断言
        assertNotNull(parkingId);
        ParkingDO parking = parkingMapper.selectById(parkingId);
        assertNotNull(parking);
        assertEquals("测试停车场", parking.getName());
        assertEquals(100, parking.getCapacity());
    }

    @Test
    public void testUpdateParking() {
        // 先创建
        ParkingDO parking = new ParkingDO();
        parking.setName("原停车场");
        parking.setCapacity(50);
        parkingMapper.insert(parking);

        // 准备更新参数
        ParkingSaveReqVO reqVO = new ParkingSaveReqVO();
        reqVO.setId(parking.getId());
        reqVO.setName("更新后停车场");
        reqVO.setCapacity(100);

        // 调用
        parkingService.updateParking(reqVO);

        // 断言
        ParkingDO updated = parkingMapper.selectById(parking.getId());
        assertEquals("更新后停车场", updated.getName());
        assertEquals(100, updated.getCapacity());
    }

    @Test
    public void testDeleteParking() {
        // 先创建
        ParkingDO parking = new ParkingDO();
        parking.setName("待删除停车场");
        parkingMapper.insert(parking);

        // 调用删除
        parkingService.deleteParking(parking.getId());

        // 断言
        ParkingDO deleted = parkingMapper.selectById(parking.getId());
        assertNull(deleted);
    }
}
