package airrescuechecklist

import (
	"bytes"
	"testing"
)

func TestAirRescuerChecklistModelTableNameAndBeforeCreate(t *testing.T) {
	var header AirRescuerChecklist
	if got := header.TableName(); got != "air_rescuer_checklists" {
		t.Fatalf("unexpected checklist table name: %s", got)
	}

	if err := header.BeforeCreate(nil); err != nil {
		t.Fatalf("BeforeCreate checklist: %v", err)
	}
	if len(header.ID) == 0 {
		t.Fatalf("expected checklist id generated")
	}

	existingID := []byte("1234567890123456")
	header2 := AirRescuerChecklist{ID: append([]byte(nil), existingID...)}
	if err := header2.BeforeCreate(nil); err != nil {
		t.Fatalf("BeforeCreate checklist with existing id: %v", err)
	}
	if !bytes.Equal(header2.ID, existingID) {
		t.Fatalf("expected existing checklist id preserved")
	}
}

func TestAirRescuerChecklistItemModelTableNameAndBeforeCreate(t *testing.T) {
	var item AirRescuerChecklistItem
	if got := item.TableName(); got != "air_rescuer_checklist_items" {
		t.Fatalf("unexpected checklist item table name: %s", got)
	}

	if err := item.BeforeCreate(nil); err != nil {
		t.Fatalf("BeforeCreate checklist item: %v", err)
	}
	if len(item.ID) == 0 {
		t.Fatalf("expected checklist item id generated")
	}

	existingID := []byte("abcdefghijklmnop")
	item2 := AirRescuerChecklistItem{ID: append([]byte(nil), existingID...)}
	if err := item2.BeforeCreate(nil); err != nil {
		t.Fatalf("BeforeCreate checklist item with existing id: %v", err)
	}
	if !bytes.Equal(item2.ID, existingID) {
		t.Fatalf("expected existing checklist item id preserved")
	}
}
