package main

import (
	"flag"
	"fmt"
	"io"
	"os"
	"time"
)

const finalWord = "Go!"

// const countDownStart = 3

type Sleeper interface {
	Sleep()
}

// type DefaultSleeper struct{}

// func (d *DefaultSleeper) Sleep() {
// 	time.Sleep(1 * time.Second)
// }

type ConfigurableSleeper struct {
	duration time.Duration
	sleep    func(time.Duration)
}

func (c *ConfigurableSleeper) Sleep() {
	c.sleep(c.duration)
}

func Countdown(out io.Writer, sleeper Sleeper, count int) {
	for i := count; i > 0; i-- {
		fmt.Fprint(out, i, "\n")
		sleeper.Sleep()
	}

	fmt.Fprint(out, finalWord, "\n")
}

func main() {
	count := flag.Int("count", 3, "Countdown start number")
	seconds := flag.Float64("seconds", 1, "Number of sleep seconds between count calls")
	flag.Parse()

	sleeper := &ConfigurableSleeper{time.Duration(*seconds * float64(time.Second)), time.Sleep}
	Countdown(os.Stdout, sleeper, *count)
}
