package publicreport

import (
	"context"
	"fmt"

	"github.com/Gleipnir-Technology/bob"
	"github.com/Gleipnir-Technology/bob/dialect/psql"
	"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
	//"source.gleipnir.technology/Gleipnir/nidus-sync/config"
	"source.gleipnir.technology/Gleipnir/nidus-sync/db"
	"source.gleipnir.technology/Gleipnir/nidus-sync/db/models"
	"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
	//"github.com/google/uuid"
	//"github.com/rs/zerolog/log"
	"github.com/stephenafamo/scan"
)

func compliance(ctx context.Context, public_id string, report types.PublicReport) (*types.PublicReportCompliance, error) {
	row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
		sm.Columns(
			models.PublicreportCompliances.Columns.AccessInstructions,
			models.PublicreportCompliances.Columns.AvailabilityNotes,
			models.PublicreportCompliances.Columns.Comments,
			models.PublicreportCompliances.Columns.GateCode,
			models.PublicreportCompliances.Columns.HasDog,
			models.PublicreportCompliances.Columns.PermissionType,
			models.PublicreportCompliances.Columns.ReportID,
			models.PublicreportCompliances.Columns.ReportPhoneCanText,
			models.PublicreportCompliances.Columns.Submitted,
			models.PublicreportCompliances.Columns.WantsScheduled,
		),
		//sm.From(psql.Quote("publicreport", "compliance")).As("publicreport.compliance"),
		sm.From(models.PublicreportCompliances.NameAs()),
		sm.Where(models.PublicreportCompliances.Columns.ReportID.EQ(
			psql.Arg(report.ID),
		)),
	), scan.StructMapper[types.PublicReportCompliance]())
	if err != nil {
		return nil, fmt.Errorf("query compliance: %w", err)
	}
	copyReportContent(report, &row.PublicReport)
	return &row, nil

}
