package main

import (
	"errors"
	"fmt"
)

// ErrAccountInactive adalah sentinel error untuk akun yang tidak aktif.
var ErrAccountInactive = errors.New("akun tidak aktif")

// Bagian "sebelum": nama-nama di bawah legal bagi compiler, tetapi
// menyimpang dari konvensi komunitas Go (snake_case, awalan get, ALL_CAPS).

type user_account_data struct {
	user_id       int
	user_name     string
	email_address string
	ACTIVE_STATUS bool
}

func (u user_account_data) get_user_name() string {
	return u.user_name
}

func (u user_account_data) get_email_address() string {
	return u.email_address
}

// Bagian "sesudah": nama singkat, MixedCaps, getter tanpa awalan Get,
// interface berakhiran -er, dan error berawalan Err.

type UserAccount struct {
	id     int
	name   string
	email  string
	active bool
}

// Notifier menyampaikan pesan keluar dari sistem.
type Notifier interface {
	Notify(message string) error
}

// NewUserAccount membuat akun baru yang siap dipakai.
func NewUserAccount(id int, name, email string) *UserAccount {
	return &UserAccount{id: id, name: name, email: email, active: true}
}

// Name mengembalikan nama pemilik akun tanpa awalan Get.
func (u *UserAccount) Name() string {
	return u.name
}

// Email mengembalikan alamat surel pemilik akun tanpa awalan Get.
func (u *UserAccount) Email() string {
	return u.email
}

// Notify meneruskan pesan ke pemilik akun.
func (u *UserAccount) Notify(message string) error {
	if !u.active {
		return fmt.Errorf("notify %s: %w", u.email, ErrAccountInactive)
	}
	fmt.Printf("notifikasi ke %s: %s\n", u.email, message)
	return nil
}

func main() {
	old := user_account_data{
		user_id:       1,
		user_name:     "Budi",
		email_address: "budi@example.com",
		ACTIVE_STATUS: true,
	}
	fmt.Println("sebelum :", old.get_user_name(), old.get_email_address())

	account := NewUserAccount(2, "Siti", "siti@example.com")
	fmt.Println("sesudah:", account.Name(), account.Email())

	err := account.Notify("Tagihan bulanan sudah terbit")
	fmt.Println("hasil notifikasi:", err)
}
