package models

import (
	"database/sql"
	"time"
)

type InvoiceItem struct {
	BaseModel
	Description string       `json:"description"`
	Quantity    int64        `json:"quantity"`
	Unit        string       `json:"unit"`
	PriceCents  int64        `json:"priceCents" gorm:"column:price_cents"`
	InvoiceID   uint         `json:"invoiceId"`
}

type InvoiceItemResponse struct {
	BaseModel
	ID          uint         `json:"id" gorm:"primaryKey"`
	CreatedAt   time.Time    `json:"createdAt"`
	UpdatedAt   time.Time    `json:"updatedAt"`
	DeletedAt   sql.NullTime `json:"deletedAt" gorm:"index"`
	Description string       `json:"description"`
	Quantity    int64        `json:"quantity"`
	Unit        string       `json:"unit"`
	PriceCents  int64        `json:"priceCents" gorm:"column:price_cents"`
	InvoiceID   uint         `json:"invoiceId"`
}

// ConvertSliceOfInvoiceItemToResponse converts a slice of InvoiceItem models to a slice of InvoiceItemResponse models
func ConvertInvoiceItemToResponse(items []InvoiceItem) []InvoiceItemResponse {
	var itemResponses []InvoiceItemResponse
	for _, item := range items {
		itemResponse := InvoiceItemResponse{
			BaseModel: BaseModel{
				ID:        item.ID,
				CreatedAt: item.CreatedAt,
				UpdatedAt: item.UpdatedAt,
			},
			Description: item.Description,
			Quantity:    item.Quantity,
			Unit:        item.Unit,
			PriceCents:  item.PriceCents,
			InvoiceID:   item.InvoiceID,
		}
		itemResponses = append(itemResponses, itemResponse)
	}
	return itemResponses
}

func (InvoiceItem) Update() (bool, error) {
	return false, nil
}
func (InvoiceItem) Create() (bool, error) {
	return false, nil
}
func (InvoiceItem) Delete() (bool, error) {
	return false, nil
}
