package com.writeoff.module.system.service;

import com.writeoff.common.api.PageResult;
import com.writeoff.module.system.model.PlatformRoleInfo;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PlatformRoleService {
    private final JdbcTemplate jdbcTemplate;

    private static final RowMapper<PlatformRoleInfo> ROLE_ROW_MAPPER = (rs, n) -> new PlatformRoleInfo(
            rs.getLong("id"),
            rs.getString("role_code"),
            rs.getString("role_name"),
            rs.getString("status")
    );

    public PlatformRoleService(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public PageResult<PlatformRoleInfo> list() {
        List<PlatformRoleInfo> list = jdbcTemplate.query(
                "SELECT id, role_code, role_name, status FROM platform_role WHERE is_deleted=0 ORDER BY id DESC",
                ROLE_ROW_MAPPER
        );
        return new PageResult<PlatformRoleInfo>(list, list.size(), 1, 100);
    }
}
