package main

import (
	"fmt"
	"encoding/json"
	
 	"github.com/aws/aws-lambda-go/events"
 	"github.com/aws/aws-lambda-go/lambda"
)

type User struct {
	Username string
	FirstName string
	LastName string
	ListOfTasks []Task
}

type Project struct {
	Name string
	Description string
	Leader User
	ListOfTasks []Task
}

type Task struct {
	Title string
	Description string
	UsersOnTask []User
	Date string
	TaskProject Project
}


func main() {
	lambda.Start(Handler)
}

func Handler() (events.APIGatewayProxyResponse, error) {
 	// Getting JSON as []byte
 	b, err := convertTasksToJSON()
 	if err != nil {
 		fmt.Println("error:", err)
 	}

 	return events.APIGatewayProxyResponse {
		Body:       string(b[:]),
		StatusCode: 200,
	}, nil
}

func convertTasksToJSON() ([]byte, error) {
	user1 := User {
 		Username: "emirbarucija",
 		FirstName: "Emir",
 		LastName: "Baručija",
	}
	
	user2 := User {
		Username: "noviUser",
		FirstName: "Novi",
		LastName: "User",
	}


	project1 := Project {
		Name: "GO language project",
		Description: "Making Web API in GO language",
		Leader: user1,
	}

	project2 := Project {
		Name: "Movie collection",
		Description: "Collection of movies, listed by categories. Make Web API in Java, and connect it with frontend application",
		Leader: user2,
	}


 	task1 := Task {
 		Title: "First task",
 		Description: "This is my first task in GO language",
 		UsersOnTask: []User{user1},
		Date: "10.04.2018.",
		TaskProject: project1, 
 	}

 	task2 := Task {
 		Title: "Second task",
 		Description: "This is my second task in GO language",
 		UsersOnTask: []User{user1},
		Date: "14.04.2018.",
		TaskProject: project1, 
	}

	task3 := Task {
		Title: "Models in Java",
		Description: "The goal of task is to make some models for Java application",
		UsersOnTask: []User{user2},
		Date: "05.02.2018.",
		TaskProject: project2,
	}

	task4 := Task {
		Title: "Controllers in Java",
		Description: "The goal is to make controllers for CRUD operations on models",
		UsersOnTask: []User{user1, user2},
		Date: "15.02.2018.",
		TaskProject: project2,
	}

	task5 := Task {
		Title: "Correct menu items positions",
		Description: "Items in menu need to be corrected via CSS, all items should be of the same size and aligned in the same way",
		UsersOnTask: []User{user1},
		Date: "12.03.2018.",
		TaskProject: project2,
	}

	task6 := Task {
		Title: "Diplay entries from database in list",
		Description: "Categories from the database need to be displayed in the list of the Categories menu",
		UsersOnTask: []User{user1, user2},
		Date: "24.03.2018.",
		TaskProject: project2,
	}

	project1.ListOfTasks = []Task{task1, task2}
	project2.ListOfTasks = []Task{task3, task4, task5, task6}

	user1.ListOfTasks = []Task{task1, task2, task4, task5, task6}
	user2.ListOfTasks = []Task{task3, task4, task6}


	tasks := []Task{task1, task2, task3, task4, task5, task6}
	b, err := json.Marshal(tasks)
	return b, err
}

func (u User) String() string {
	return fmt.Sprintf("Username: %v\nFirst name: %v\nLast name: %v\nTAsks: %v", u.Username, u.FirstName, u.LastName, u.ListOfTasks)
}

func (t Task) String() string {
	return fmt.Sprintf("Title: %v\nDescription: %v\nUsers: %v\nDate: %v\nProject: %v", t.Title, t.Description, t.UsersOnTask, t.Date, t.TaskProject)
}

func (p Project) String() string {
	return fmt.Sprintf("Name: %v\nDescription: %v\nLeader: %v", p.Name, p.Description, p.Leader)
}