// Copyright (C) 2019 Marius Schellenberger

package core

import "html/template"

type Page struct {
	Title      string        `json:"title"`
	StoreTitle string        `json:"store_title"`
	Markdown   string        `json:"markdown"`
	TOC        template.HTML `json:"toc"`
	HTML       template.HTML `json:"html"`
	Created    string        `json:"created"`
	Updated    string        `json:"updated"`
	Perm       Permission    `json:"perm"`
}

type Pages []Page

func (p Pages) Len() int           { return len(p) }
func (p Pages) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p Pages) Less(i, j int) bool { return p[i].StoreTitle < p[j].StoreTitle }

type UpdatedPages []Page

func (p UpdatedPages) Len() int           { return len(p) }
func (p UpdatedPages) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p UpdatedPages) Less(i, j int) bool { return p[i].Updated > p[j].Updated }

type Section struct {
	Name    string
	User    bool
	Members []string
}

type Sections []Section

func (s Sections) Len() int           { return len(s) }
func (s Sections) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s Sections) Less(i, j int) bool { return s[i].Name < s[j].Name }

type SectionPage struct {
	Section string
	Pages   UpdatedPages
}

type SectionPages []SectionPage

func (s SectionPages) Len() int           { return len(s) }
func (s SectionPages) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s SectionPages) Less(i, j int) bool { return s[i].Section < s[j].Section }

type User struct {
	Username string
	Password string
	Created  string
	Secret   string
	Admin    bool
	Locked   int
}

type Users []User

func (u Users) Len() int           { return len(u) }
func (u Users) Swap(i, j int)      { u[i], u[j] = u[j], u[i] }
func (u Users) Less(i, j int) bool { return u[i].Username < u[j].Username }

type Result struct {
	Title      string
	Section    string
	StoreTitle string
	HTML       template.HTML
}

type Config struct {
	DataDir      string `json:"data_dir,omitempty"`
	User         string `json:"user,omitempty"`
	Group        string `json:"group,omitempty"`
	ListenAddr   string `json:"listen_addr,omitempty"`
	LogFile      string `json:"log_file,omitempty"`
	Version      string `json:"-"`
	Secret       string `json:"secret,omitempty"`
	Admin        bool   `json:"admin,omitempty"`
	Foreground   bool   `json:"foreground,omitempty"`
	SecureCookie bool   `json:"secure_cookie,omitempty"`
	Debug        bool   `json:"debug,omitempty"`
}
