package core

import (
	"fmt"
	"github.com/pkg/errors"
	"log"
	"io"
	"bytes"
	"sync"
)

type basejob struct {
	// Function to call on Collect
	collectfunc func(c *Collector) error

	// Global lock for all following members.
	mu sync.Mutex

	// Unique identifier of this job.
	id JobId

	// The state the job is currently in.
	state JobState

	// When state is set to Failed, contains the reason
	// for this failure.
	failure error

	// Recorded logs for this job.
	logged bytes.Buffer
}

func (bj *basejob) Id() JobId {
	bj.mu.Lock()
	defer bj.mu.Unlock()

	return bj.id
}

func (bj *basejob) State() JobState {
	bj.mu.Lock()
	defer bj.mu.Unlock()

	return bj.state
}

func (bj *basejob) Error() error {
	bj.mu.Lock()
	defer bj.mu.Unlock()

	return bj.failure
}

func (bj *basejob) Collect(c *Collector) error {
	return errors.New("not implemented")
}

func (bj *basejob) Log(v ...interface{}) {
	log.Output(3, fmt.Sprint(v...))
}

func (bj *basejob) Logf(format string, v ...interface{}) {
	log.Output(3, fmt.Sprintf(format, v...))
}

func (bj *basejob) Logs() io.Reader {
	panic("not yet implemented")
}