// repository/permission_repository.go
package repository

import "database/sql"

type PermissionRepository struct {
	DB *sql.DB
}

func NewPermissionRepository(db *sql.DB) *PermissionRepository {
	return &PermissionRepository{DB: db}
}

func (r *PermissionRepository) GetPermissionsByRoleID(roleID int64) ([]string, error) {
	rows, err := r.DB.Query(`
		SELECT route
		FROM mkdf_rol_per
		WHERE role_id = $1 AND can_access = true
	`, roleID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	perms := []string{}
	for rows.Next() {
		var route string
		if err := rows.Scan(&route); err == nil {
			perms = append(perms, route)
		}
	}
	return perms, nil
}
