package main

import (
	"encoding/json"
	"os"
	"path/filepath"
)

type Activation struct {
	Activated   bool   `json:"activated"`
	StudentId   string `json:"studentId,omitempty"`
	StudentName string `json:"studentName,omitempty"`
	Code        string `json:"code,omitempty"`
}

func activationFile(dataDir string) string {
	return filepath.Join(dataDir, "activation.json")
}

func loadActivation(dataDir string) (*Activation, error) {
	f := activationFile(dataDir)
	data, err := os.ReadFile(f)
	if err != nil {
		return nil, err
	}
	var a Activation
	err = json.Unmarshal(data, &a)
	return &a, err
}

func saveActivation(dataDir string, a *Activation) error {
	if err := os.MkdirAll(dataDir, 0755); err != nil {
		return err
	}
	f := activationFile(dataDir)
	data, err := json.MarshalIndent(a, "", "  ")
	if err != nil {
		return err
	}
	return os.WriteFile(f, data, 0644)
}
