package cn.reghao.tnb.file.app.zdisk.db.repository;

import cn.reghao.jutil.jdk.web.db.Page;
import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.tnb.file.app.zdisk.db.mapper.CamDeviceMapper;
import cn.reghao.tnb.file.app.zdisk.db.mapper.CamRecordMapper;
import cn.reghao.tnb.file.app.zdisk.model.po.CamDevice;
import cn.reghao.tnb.file.app.zdisk.model.query.CamDeviceQuery;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author reghao
 * @date 2025-09-06 16:17:50
 */
@Repository
public class DiskCamRepository {
    private CamDeviceMapper camDeviceMapper;
    private CamRecordMapper camRecordMapper;

    public DiskCamRepository(CamDeviceMapper camDeviceMapper, CamRecordMapper camRecordMapper) {
        this.camDeviceMapper = camDeviceMapper;
        this.camRecordMapper = camRecordMapper;
    }

    public CamDevice getCamDevice(long camId, long createBy) {
        long loginUser = UserContext.getUserId();
        CamDeviceQuery camDeviceQuery = new CamDeviceQuery.Builder()
                .addBy(loginUser)
                .camId(camId)
                .build();
        Page page = new Page(1, 1);
        List<CamDevice> camDeviceList = camDeviceMapper.findCamDeviceQueryByPage(page, camDeviceQuery);
        return camDeviceList.isEmpty() ? null : camDeviceList.get(0);
    }
}
