package com.ai.da.mapper.primary;

import com.ai.da.mapper.primary.entity.SubscriptionPlan;
import com.ai.da.model.vo.SubscriptionPlanVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface SubscriptionPlanMapper extends BaseMapper<SubscriptionPlan> {

    /**
     * 关联查询订阅计划信息（包含管理员邮箱）- 分页
     */
    @Select("""
            SELECT sp.*, 
                   a.user_email AS adminAccEmail, 
                   a.user_name AS adminAccName,
                   o.name AS organizationName
            FROM t_subscription_plan sp
            LEFT JOIN t_account a ON sp.admin_acc_id = a.id
            LEFT JOIN t_organization o on sp.organization_id = o.id
            ${ew.customSqlSegment}
            """)
    Page<SubscriptionPlanVO> selectWithEmailPage(Page<SubscriptionPlanVO> page,
                                                 @Param(Constants.WRAPPER) Wrapper<?> wrapper);
}
