package model

import (
	"encoding/json"
	"time"

	"gorm.io/gorm"
)

// PlatformApp represents a platform-level application.
// Reference: Chatwoot PlatformApp model + P2B M12 spec
type PlatformApp struct {
	ID          uint           `gorm:"primaryKey" json:"id"`
	Name        string         `gorm:"size:255;not null" json:"name"`
	Description string         `gorm:"type:text" json:"description"`
	Icon        string         `gorm:"size:255" json:"icon"`
	URL         string         `gorm:"size:512" json:"url"`
	Config      json.RawMessage `gorm:"type:jsonb" json:"config"`
	Active      bool           `gorm:"default:true" json:"active"`
	CreatedAt   time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`

	Permissibles []Permissible `gorm:"foreignKey:PlatformAppID" json:"permissibles,omitempty"`
}

func (PlatformApp) TableName() string { return "platform_apps" }