package models

import "brainminder.speedtech.it/internal/database"

type ItemShareModel struct {
	DB *database.DB
}

type ItemShare struct {
	Id             int64  `db:"id"`
	Token          string `db:"token"`
	Summary        string `db:"summary"`
	Item_id        int64  `db:"item_id"`
	Read           int    `db:"crypted"`
	Update         int    `db:"hidden"`
	Start_datetime string `db:"start_datetime"`
	End_datetime   string `db:"end_datetime"`
	password       string `db:"password"`
}

func (model *ItemShareModel) Create(ItemShare *ItemShare) (int64, error) {
	ctx, cancel := database.GetContext()
	defer cancel()

	query := `INSERT INTO bm_items_share (title, description, icon, hidden) VALUES (:title, :description, :icon, :hidden)`

	result, err := model.DB.NamedExecContext(ctx, query, ItemShare)
	if err != nil {
		return 0, err
	}

	id, err := result.LastInsertId()
	if err != nil {
		return 0, err
	}

	return id, err
}
