package com.ga.core.mapper.income;

import com.ga.core.vo.income.YearEndStatementExcelVO;
import com.ga.core.vo.income.YearEndStatementResp;
import com.ga.core.vo.income.YearEndStatementSearchParam;
import com.ga.core.vo.income.YearEndStatementVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.cursor.Cursor;

import java.util.List;

@Mapper
public interface YearEndStatementMapper {

    List<YearEndStatementResp> selectList(YearEndStatementSearchParam param);

    YearEndStatementResp selectDetailById(@Param("statementId") Long statementId);

    /** 엑셀 다운로드 전용 (cursor 스트리밍) */
    Cursor<YearEndStatementExcelVO> selectExcelCursor(YearEndStatementSearchParam param);

    /**
     * 연도 전체 UPSERT 생성.
     * agent_annual_income 데이터를 가져와 statement 행 생성/갱신.
     * agentIds 가 null 이면 전체 설계사 대상.
     */
    int upsertByYear(@Param("year") int year,
                     @Param("agentIds") List<Long> agentIds);

    /** 발급 처리 — file_path/file_format/file_status='GENERATED'/generated_at UPDATE */
    int updateGenerated(@Param("statementId") Long statementId,
                        @Param("filePath") String filePath,
                        @Param("fileFormat") String fileFormat);

    /** 발송 처리 — ids 일괄 UPDATE: status=SENT, sent_at=now() */
    int updateSent(@Param("ids") List<Long> ids,
                   @Param("sentTo") String sentTo);
}
