package org.wcs.serve.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.wcs.factory.AppServeResponseFactory;
import org.wcs.mapper.intf.AppBaseLedService;
import org.wcs.model.dto.serve.led.AddBaseLedReq;
import org.wcs.model.dto.serve.led.QueryLedReq;
import org.wcs.model.dto.serve.led.UpdateBaseLedReq;
import org.wcs.model.po.app.AppBaseLed;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.led.QueryLedVo;
import org.wcs.serve.service.intf.ILedService;
import org.wcs.utils.AppBeanUtils;
import org.wcs.utils.AppUUIDUtils;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class LedService implements ILedService {

    private final AppBaseLedService baseLedService;

    /**
     * 查询LED屏基础资料
     * @param queryLedReq 查询LED屏基础资料请求
     * @return 查询结果
     */
    @Override
    public AppServeDataResponse<List<QueryLedVo>> queryLed(QueryLedReq queryLedReq) {
        List<AppBaseLed> appBaseLedList = baseLedService.queryLed(queryLedReq);
        if(appBaseLedList == null) {
            return AppServeResponseFactory.fail("查询失败，数据服务异常",  null);
        }
        List<QueryLedVo> queryLedVos = AppBeanUtils.copyListProperties(appBaseLedList, QueryLedVo::new);
        return AppServeResponseFactory.success("查询成功", queryLedVos);
    }

    /**
     * 添加LED屏基础资料
     * @param addBaseLedReq 添加LED屏基础资料请求
     * @return 添加结果
     */
    @Override
    public AppServeResponse addBaseLed(AddBaseLedReq addBaseLedReq) {
        AppBaseLed appBaseLed = new AppBaseLed();
        appBaseLed.setId(AppUUIDUtils.getNewUUID());
        appBaseLed.setLedIp(addBaseLedReq.getLedIp());
        appBaseLed.setLedBrand(addBaseLedReq.getLedBrand());
        appBaseLed.setHeight(addBaseLedReq.getHeight());
        appBaseLed.setWidth(addBaseLedReq.getWidth());
        appBaseLed.setColorType(addBaseLedReq.getColorType());
        appBaseLed.setLocation(addBaseLedReq.getLocation());
        appBaseLed.setIsExternal(addBaseLedReq.getIsExternal());
        appBaseLed.setRemark(addBaseLedReq.getRemark());
        int result = baseLedService.insert(appBaseLed);
        if(result <= 0) {
            return AppServeResponseFactory.fail("添加失败，数据服务异常", null);
        }
        return AppServeResponseFactory.success("添加成功", null);
    }

    /**
     * 修改LED屏基础资料
     * @param updateBaseLedReq 修改LED屏基础资料请求
     * @return 修改结果
     */
    @Override
    public AppServeResponse updateBaseLed(UpdateBaseLedReq updateBaseLedReq) {
        AppBaseLed appBaseLed = new AppBaseLed();
        appBaseLed.setId(updateBaseLedReq.getId());
        appBaseLed.setLedIp(updateBaseLedReq.getLedIp());
        appBaseLed.setLedBrand(updateBaseLedReq.getLedBrand());
        appBaseLed.setHeight(updateBaseLedReq.getHeight());
        appBaseLed.setWidth(updateBaseLedReq.getWidth());
        appBaseLed.setColorType(updateBaseLedReq.getColorType());
        appBaseLed.setLocation(updateBaseLedReq.getLocation());
        appBaseLed.setIsExternal(updateBaseLedReq.getIsExternal());
        appBaseLed.setRemark(updateBaseLedReq.getRemark());
        int result = baseLedService.update(appBaseLed);
        if(result <= 0) {
            return AppServeResponseFactory.fail("修改失败，数据服务异常", null);
        }
        return AppServeResponseFactory.success("修改成功", null);
    }

    /**
     * 删除LED屏基础资料
     * @param id LED屏基础资料ID
     * @return 删除结果
     */
    @Override
    public AppServeResponse deleteBaseLed(String id) {
        int delete = baseLedService.delete(id);
        if(delete <= 0) {
            return AppServeResponseFactory.fail("删除失败，数据服务异常", null);
        }
        return AppServeResponseFactory.success("删除成功", null);
    }
}
