package gencsv

import (
	excelread "business-engine/internal/excel_read"
	"encoding/csv"
	"io"
	"os"

	"github.com/gocarina/gocsv"
)

func GeneratePayrollStatementCSV(stmts []excelread.PayrollStatement) error {
	file, err := os.Create("payroll_statement.csv")
	if err != nil {
		return err
	}
	defer file.Close()

	gocsv.SetCSVWriter(func(out io.Writer) *gocsv.SafeCSVWriter {
		writer := csv.NewWriter(out)
		writer.Comma = ';'
		return gocsv.NewSafeCSVWriter(writer)
	})

	if err := gocsv.MarshalFile(&stmts, file); err != nil {
		return err
	}
	return nil
}

func GenerateEmployeesOnTime(employeesontime []excelread.EmployeeOnTime) error {
	file, err := os.Create("employees_on_time.csv")
	if err != nil {
		return err
	}
	defer file.Close()

	if err := gocsv.MarshalFile(&employeesontime, file); err != nil {
		return err
	}
	return nil
}
